
<?php get_main_menu("receptionist") ?>

   <br/>
   <div style="width:90%; margin-left:auto; margin-right:auto;">
    <div class="form_title">

            <?php echo $_REQUEST["action"];?> Order <?php echo $row_get_branch_by_id['name']?>
    </div>
    <div class="box"> 
<?php
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "order")) {
	
  $insertSQL = sprintf("INSERT INTO `order` (created_by, created_date, record_status, customer_id, branch_id, order_no) VALUES (%s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($loggedin_id, "int"),
                       GetSQLValueString(date("y-m-d"), "date"),
                       GetSQLValueString($_POST['record_status'], "text"),
                       GetSQLValueString($_POST['customer_id'], "int"),
                       GetSQLValueString($_SESSION["branch_id"], "int"),
                       GetSQLValueString($_POST['order_no'], "text"));

  mysql_select_db($database_drycleaners_conn, $drycleaners_conn);
  $Result1 = mysql_query($insertSQL, $drycleaners_conn) or die(mysql_error());
  
    if(mysql_affected_rows($drycleaners_conn)>0){
	  redirect_drycleaners("order_view","2");
	  }
}

mysql_select_db($database_drycleaners_conn, $drycleaners_conn);
$query_customer = "SELECT person.first_name, person.last_name, customer.id
  FROM    drycleaners.customer customer
       INNER JOIN
          drycleaners.person person
       ON (customer.person_id = person.id)";
$customer = mysql_query($query_customer, $drycleaners_conn) or die(mysql_error());
$row_customer = mysql_fetch_assoc($customer);
$totalRows_customer = mysql_num_rows($customer);

if(isset($_REQUEST['order_edit'])){
$colname_order = "-1";
if (isset($_GET['id'])) {
  $colname_order = $_GET['id'];
}
mysql_select_db($database_drycleaners_conn, $drycleaners_conn);
$query_order = sprintf("SELECT * FROM drycleaners.order WHERE id = %s", GetSQLValueString($colname_order, "int"));
$order = mysql_query($query_order, $drycleaners_conn) or die(mysql_error());
$row_order = mysql_fetch_assoc($order);
$totalRows_order = mysql_num_rows($order);
}


mysql_select_db($database_drycleaners_conn, $drycleaners_conn);
$query_order_last_insert = "SELECT * FROM drycleaners.order ORDER BY id DESC LIMIT 0 ,1";
$order_last_insert = mysql_query($query_order_last_insert, $drycleaners_conn) or die(mysql_error());
$row_order_last_insert = mysql_fetch_assoc($order_last_insert);
$totalRows_order_last_insert = mysql_num_rows($order_last_insert);

?>
<form action="<?php echo $editFormAction; ?>" method="post" name="order" id="order">
  <table align="left">
   <tr valign="baseline">
      <td nowrap="nowrap" align="left">Order No:</td>
      <td><input type="hidden" name="id" value="<?php echo $row_order['id']; ?>" size="32" />
      <input type="hidden" name="order_no" value="<?php if(isset($_REQUEST['order_edit'])){echo $row_order['order_no'];} else{ echo "Or".(1+$row_order_last_insert['id']);} ?>" size="32" /><?php if(isset($_REQUEST['order_edit'])){echo $row_order['order_no'];} else{ echo "Or".(1+$row_order_last_insert['id']);} ?>
      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="left">Customer:</td>
      <td><select name="customer_id">
        <?php 
do {  
?>
        <option value="<?php echo $row_customer['id']?>" ><?php echo $row_customer['id']."".$row_customer['first_name']." ".$row_customer['last_name']?></option>
        <?php
} while ($row_customer = mysql_fetch_assoc($customer));
?>
      </select></td>
    </tr>
    <tr> </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="left">&nbsp;</td>
      <td>	  <?php if(isset($_REQUEST['order_edit'])){	
		echo"<input name='update' type='submit' value='UPDATE' id='submit'/>";
		echo" <a href='.?order_view'><input name='add' type='button' value='Cancel' id='submit'/></a>";
		echo"<input type='hidden' name='MM_update' value='order_form' />";	
		}
		else{
			echo"<input name='save' type='submit' value='Continue' id='submit'/>";
			echo" <a href='.?order_view'><input name='add' type='button' value='Cancel' id='submit'/></a>";
			echo"<input type='hidden' name='MM_insert' value='order_form' />";	
			}
		?></td>
    </tr>
  </table>
  <input type="hidden" name="record_status" value="active" />
  <input type="hidden" name="MM_insert" value="order" />
</form>
<?php
mysql_free_result($customer);
?>
</body>